<template>
    <el-form ref="form" :model="form" label-width="80px">
  <!-- <el-form-item label="小节名称">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
    <el-form-item label="课程简介">
    <el-input type="textarea" v-model="form.lessionInfo"></el-input>
  </el-form-item>
      <el-form-item label="videoId">
    <el-input disabled  v-model="form.videoId"></el-input>
  </el-form-item>
    <el-form-item label="课程时长">
    <el-input  v-model="form.lengthTime"></el-input>
  </el-form-item> -->
    <el-form-item label="第几小节">
        <el-input-number disabled="" v-model="form.num" :min="1" :step="1" ></el-input-number> 
        &nbsp;
  </el-form-item>
  <updatevideo v-bind:updatedvideoId="updatedvideoId"></updatevideo>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button @click="$attrs.dialog()" >取消</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import { asyncuploadLession } from "../../plugins/api.js";
import updatevideo from "@/components/update.vue";
export default {
  data() {
    return {
      form: {
        name: "",
        num: 1,
        course_ID: "",
        lessionInfo: "",
        videoId: "",
        lengthTime: ""
      }
    };
  },
  mounted() {
    this.start();
  },
  methods: {
    async onSubmit() {
      try {
        let data = await asyncuploadLession(this.form);
        console.log(data);
        this.$attrs.start();
        this.$message({
          message: "恭喜你，添加成功",
          type: "success"
        });
        this.$attrs.dialogFormVisible();
      } catch (err) {
        this.$message.error("错了哦，添加失败:" + err);
      }
    },
    start() {
      console.log(this.$attrs.course)
      if (this.$attrs.course) {
        this.form.course_ID = this.$attrs.course.Course.ID;
        this.form.num = this.$attrs.course.Lession.length + 1;
      }
    },
    updatedvideoId(data) {
      this.form.videoId = data;
    }
  },
  components: {
    updatevideo
  }
};
</script>

<style scoped>
</style>
